function ljdt(A,B)
p=roots(A); % 求系统极点
q=roots(B); % 求系统零点
p=p';
q=q';
x=max(abs([p q 1])); % 确定纵坐标范围
x=x+0.1;
y=x; % 确定横坐标范围
hold on
axis([-x x -y y])
w=0:pi/300:2*pi;
t=exp(1i*w);
plot(t)
axis('square')
plot([-x x],[0 0])
plot([0 0],[-y y])
text(0.1,x,'jIm[z]')
text(y,1/10,'Re[z]')
plot(real(p),imag(p),'x')
plot(real(q),imag(q),'o')
title('零极点图');hold off

%% example 6-7
clear,clc,clf
num=[0.55 0.5 -1];
den=[1 -0.5 -0.45];
x0=[2 3];y0=[1 2];
N=50;
n=[0:N-1]';
x=0.7.^n;
Zi=filtic(num,den,y0,x0);
[y,Zf]=filter(num,den,x,Zi);
plot(n,x,'r-',n,y,'b--');title('响应');grid 
xlabel('n');
ylabel('x(n)-y(n)');
legend('输入x','输出y')

%% example 6-8
clear,clc,clf
N=32;
x_delta=zeros(1,N);
x_delta(1)=1;
p=[1 -1 0];
d=[1 0.75 0.125];
h1_delta=filter(p,d,x_delta);
subplot(211);stem(0:N-1,h1_delta,'r');
hold off
title('单位冲激响应')
x_unit=ones(1,N);
h1_unit=filter(p,d,x_unit);
subplot(212);stem(0:N-1,h1_unit,'r');
hold off
title('阶跃响应')

%% 6-9
t=linspace(1e-3,100e-3,10);
xn=sin(100*2*pi*t);
N=length(xn);
WNnk=dftmtx(N);
Xk=xn*WNnk;
subplot(1,2,1);stem(1:N,xn);
subplot(122);stem(1:N,abs(Xk));

%% 6-10
N=16;
N1=8;
n=0:N-1;
k=0:N1-1;
x1n=exp(j*pi*n/8);
X1=fft(x1n,N);
X2=fft(x1n,N1);
x2n=cos(pi*n/8);
X3=fft(x2n,N);
X4=fft(x2n,N1);
subplot(221);stem(n,abs(X1),'.');title('16点的DFT[x1(n)]')
axis([0 20 0 20]);ylabel('|X1(k)|')
subplot(222);stem(n,abs(X3),'.');title('16点的DFT[x1(n)]')
axis([0 20 0 20]);ylabel('|X2(k)|')
subplot(223);stem(k,abs(X2),'.');title('8点的DFT[x1(n)]')
axis([0 20 0 20]);ylabel('|X1(k)|')
subplot(224);stem(k,abs(X4),'.');title('8点的DFT[x1(n)]')
axis([0 20 0 20]);ylabel('|X2(k)|')
%% 6-16
% 利用FFT对叠加白噪声信号进行滤波，滤除频率为4~8Hz的波
f1=4;f2=8; 
yy=zeros(1,length(y));
for m=0:N-1
    if(m/N*dt)>f1 && m/(N*dt)<f2 || (m/(N*dt)>(1/dt-f2) && m/(N*dt)<(1/dt-f1))
        yy(m+1)=0;
    else
        yy(m+1)=y(m+1);
    end
end

